/*
    YmsgIRC - Program enabling YMSG chat clients to use IRC
    Copyright (C) 2011 Crash Daemonicus ( crashenator -at- gmail.com )

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common.h"

/*
+ Description:
	Fields, in the YMSG protocol, are kind of like variables or properties.
	Like variables, fields are identified by type, albeit given only as an number/ID - this identifies what type of value they should contain.
	However, unlike variables having names to distinguish them, Fields do not distinguish themselves from other fields of the same type.

	Fields are represented raw as a delimited string prefixed by the Field Type number, in the format <FieldNumber><Delim><Value><Delim>

	The type-number for Fields is a positive or zero value integer.

	Packets containing multiple fields have been known to have several fields of the same ID occasionally,
	but it appears that the protocol is moving towards using Items(read: objects) and Lists (read: arrays/vectors)

	Generally, Packets of their own type have the same set of allowed and required fields similar to objects. This is also the case for Items.

+ About this Implementation:
	This class allows representation of Fields as their Type and Value parts as well as a raw string.
	Since field type-numbers are 0 or greater, a value of -1 is currently used as a default and invalid value.
	The class performs "assembling" and "processing" to perform Type/Value->String and String->Type/Value translations respectively.

	This class also supports the deprecated feature of abusing the 'str' property of the class to appended several fields in string format.
	This feature is/was originally used for ease of collecting several fields before sending the data over a socket.
	However, this is being phased out in lieu of a more formal implementation such as field-vectors, item objects, etc.

*/
class YmsgField
{
    public:
        string str;
        int num;//the field type/ID identifying the type of value
        string value;//the contents of the field.
        bool processed,valid,assembled,compound;
        /*
        Processed = has usable Num/Value members present
        Assembled = has usable Str member present
            Process() = acquire Num/Value from Str
            Assemble() = acquire Str from Num/Value
        Valid = field format validated (via Process() only)
        Compound = multiple fields
        */
        
        YmsgField();
        YmsgField(const int i,const string& s, const bool bAssemble=true);
        YmsgField(const int i,const int v);
        YmsgField(const string& s);
        YmsgField(const string& s, const bool bProcess);
        void process();
        void assemble();
        
        
        const YmsgField& operator=(const string& s);
        const YmsgField& operator+=(const YmsgField& f2);//deprecate this
        bool operator==(const YmsgField& f2) const;

		vector<YmsgField> operator+(const YmsgField& f2);
		vector<YmsgField> operator+(vector<YmsgField> fields2);

		string toString();

		void debug() const;
};
